package com.mooc.yohoshop;

import android.app.Application;
import android.content.ComponentCallbacks2;

import com.alipay.sdk.app.EnvUtils;
import com.bumptech.glide.Glide;
import com.mooc.yohoshop.dao.DaoDBUtils;
import com.mooc.yohoshop.dao.UserDaoEntity;

public class App extends Application {

    private static App app;
    private boolean isLogin = true;
    private long userId = 1;

    public static App getInstance(){
        return app;
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX);
        DaoDBUtils.getInstance().init();
    }

    public void setLogin(boolean login) {
        isLogin = login;
    }

    public boolean isLogin(){
        isLogin = !new UserDaoEntity().selectAll().isEmpty();
        return isLogin;
    }

    @Override
    public void onTrimMemory(int level) {
        super.onTrimMemory(level);
        if (level == ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW){
            Glide.get(this).clearMemory();
        }
    }
}
